package com.chuanke.ckfamily.service.common.model;

import sun.misc.BASE64Encoder;

import java.io.Serializable;
import java.security.KeyPair;
import java.security.PublicKey;

/**
 * Created by wangbin on 2017/6/28.
 */
public class RSAKey implements Serializable {

    private KeyPair keyPair;

    private Long createTime;

    private Long invlidateTime;

    public RSAKey(KeyPair keyPair) {
        this.keyPair = keyPair;
        this.createTime = System.currentTimeMillis();
        this.invlidateTime = createTime + 1000*60*60*24*365;
    }

    public KeyPair getKeyPair() {
        return keyPair;
    }

    public Long getCreateTime() {
        return createTime;
    }

    public Long getInvlidateTime() {
        return invlidateTime;
    }

	public void setKeyPair(KeyPair keyPair) {
		this.keyPair = keyPair;
	}

	public void setCreateTime(Long createTime) {
		this.createTime = createTime;
	}

	public void setInvlidateTime(Long invlidateTime) {
		this.invlidateTime = invlidateTime;
	}
	public String getPublicKey() {
		PublicKey publicKey = keyPair.getPublic();
	    BASE64Encoder base64Encoder=new BASE64Encoder();
        return base64Encoder.encodeBuffer(publicKey.getEncoded());
    }
}